using IGeekFan.AspNetCore.Knife4jUI;
using Microsoft.EntityFrameworkCore;
using NLog.Web;
using RBAC.Interstructrue;
using RBAC.Interstructrue.Base;
using SmartHealthcare.Write.Api;
using System.Reflection;
using Yitter.IdGenerator;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(p =>
{
    var path = Path.Combine(AppContext.BaseDirectory, "SmartHealthcare.Write.Api.xml");
    p.IncludeXmlComments(path, true);
});
// 数据库连接
builder.Services.AddDbContext<RBACDbContext>(x =>
{
    x.UseMySql(builder.Configuration.GetConnectionString("MySQL"), new MySqlServerVersion("5.7"));
});
//中介者
builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
// 自动映射
builder.Services.AddAutoMapper(typeof(SmartHealthcareAutoMapper));
// 日志
builder.Host.UseNLog();
// 雪花id
YitIdHelper.SetIdGenerator(new IdGeneratorOptions());
// 仓储
builder.Services.AddScoped(typeof(IBaseRepository<>), typeof(BaseRepository<>));
var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    //app.UseSwaggerUI();
    app.UseKnife4UI();
}

// 启用静态文件服务
app.UseStaticFiles();

app.UseAuthorization();

app.MapControllers();

app.Run();
